# Build recipe for clisp.
#
# Copyright (c) 2017 MMPG, <mmpg@vp.pl>.
# Copyright (c) 2017 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=clisp
version=2.49
release=1

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=http://ftp.gnu.org/pub/gnu/clisp/release/${version}/$tarname

description="
A Common Lisp implementation.

In computing, CLISP is an implementation of the programming language
Common Lisp originally developed by Bruno Haible and Michael Stoll for
the Atari ST.

LISP includes an interpreter, a bytecode compiler, debugger, socket
interface, high-level foreign language interface, strong
internationalization support, and two object systems:
Common Lisp Object System (CLOS) and metaobject protocol (MOP).

It is written in C and Common Lisp. It is now part of the GNU Project
and is free software, available under the terms of the GNU General
Public License (GPL).
"

hompage=http://clisp.org
license=GPLv2

# Source documentation
docs="ANNOUNCE COPYRIGHT GNU-GPL SUMMARY"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e
    unpack "${tardir}/$tarname"
	
    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Apply to fix build failure with current readline (Thanks to BLFS)
    patch -Np1 -i \
     "${worktree}/patches/clisp/clisp-2.49-readline7_fixes-1.patch"

    # Update for hosts based on musl
    cp -f "${worktree}/archive/common/config.guess" src/build-aux/config.guess
    cp -f "${worktree}/archive/common/config.sub" src/build-aux/config.sub

    # Create a separate build directory
    rm -rf build
    mkdir build
    cd build

    ../configure --srcdir=../   \
             --prefix=/usr      \
             --docdir=$docsdir  \
             --with-libsigsegv-prefix=/usr \
             --build="$(cc -dumpmachine)"

    make -j${jobs}
    make -j${jobs} DESTDIR="$destdir" install

    #./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
    # --prefix=/usr --build="$(cc -dumpmachine)"
    #cd src/
    #make -j${jobs}
    #make -j${jobs} DESTDIR="$destdir" install

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}/"
}

